//
//  ZhuCeViewController.m
//  ForengnMenu
//
//  Created by @-@ on 16/1/20.
//  Copyright © 2016年 余旺. All rights reserved.
//

#import "ZhuCeViewController.h"

@interface ZhuCeViewController ()

@end

@implementation ZhuCeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.zhuCeBG.image = [UIImage imageNamed:@"Icon_zhuceBG"];

    
    self.phoneNumberTextField.placeholder = @"电话号码：";
     [self.phoneNumberTextField setValue:[UIColor colorWithWhite:0.7 alpha:1.0] forKeyPath:@"_placeholderLabel.textColor"];
    
    self.yanzhengmaTextField.placeholder = @"验证码：";
    [self.yanzhengmaTextField setValue:[UIColor colorWithWhite:0.7 alpha:1.0] forKeyPath:@"_placeholderLabel.textColor"];

    self.passwordTextField.placeholder = @"密码：";
    [self.passwordTextField setValue:[UIColor colorWithWhite:0.7 alpha:1.0]forKeyPath:@"_placeholderLabel.textColor"];
    
    self.rePasswordTextField.placeholder = @"确认密码：";
    [self.rePasswordTextField setValue:[UIColor colorWithWhite:0.7 alpha:1.0] forKeyPath:@"_placeholderLabel.textColor"];
    
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    button.frame = CGRectMake(0, 0, 60, 30);
    
    [button setTitle:@"<返回" forState:UIControlStateNormal];
    
    [button addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

    
    
    UILabel * l = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 40)];
    l.text = @"注册";
    l.textAlignment = NSTextAlignmentCenter;
    l.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = l;
    
    
    self.button.enabled = YES;
    self.button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [self.button setFrame:CGRectMake(174, 167, 126, 41)];
    [self.button setTitle:@"点击获取" forState:UIControlStateNormal];
    [self.button setBackgroundColor:[UIColor colorWithRed:161/255.0f green:185/255.0f blue:69/255.0f alpha:1.0f]];
    self.button.titleLabel.font = [UIFont systemFontOfSize:12];
    [self.button setTintColor:[UIColor whiteColor]];
    [self.button addTarget:self action:@selector(addButtonAction) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:self.button];
    
}


//返回
- (void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}

//触摸结束时触发收起键盘
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.view endEditing:YES];
    
}

- (IBAction)dianjiHuoquAction:(id)sender {
}


#pragma NStimer
- (void)viewWillAppear:(BOOL)animated{
    
    [self.timer invalidate];
    self.timer= [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(changeButtonName) userInfo:nil repeats:YES];
    self.button.enabled = YES;
//    [self.button setTitle:@"重新获取(10)" forState: UIControlStateNormal ];

    _myTime = 60;

}

- (void)viewWillDisappear:(BOOL)animated{
    
    [self.timer invalidate];
    
}

int a = 0;

- (void)changeButtonName{
    
    if (a == 0 ) {
        return;
    }
    
    if (_myTime > 0) {
        
        self.button.enabled = NO;
        
        _myTime--;
        
        NSString * string = [NSString stringWithFormat:@"重新获取(%d)",_myTime];
        
        [self.button setTitle:string forState:UIControlStateNormal];
        
    }else{
        
        [self.timer invalidate];
        
        NSString * string = [NSString stringWithFormat:@"点击获取"];

        [self.button setTitle:string forState:UIControlStateNormal];

        self.button.enabled = YES;

    }

}

- (void)addButtonAction{
    
    a = 1;
    
    [self.timer invalidate];
    
    [self viewWillAppear:YES];
    
}




- (IBAction)tijiaoAction:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
    
}




@end
